import type { PostsModel,postMetaModel} from '@/api/model/postsModel';
import { request } from '@/utils/request';

const Api = {
  Drafts: '/posts/drafts',
  Publish:'/posts/publish',
  Schedule:'/posts/scheduled',
  Edit:'/posts/edit',
  Delete:'/posts/delete',
  Detail:'/posts/detail',
  All:'/posts/all',
  EditMeta:'/posts/meta'
};

export function getDraftsList(d:any) {
  if(d.date)
  {
    return request.get<PostsModel>({
      url: Api.Drafts+`?page=${d.current}&pageSize=${d.pageSize}&date=${d.date}`,
    });
  }else
  {
    return request.get<PostsModel>({
      url: Api.Drafts+`?page=${d.current}&pageSize=${d.pageSize}`,
    });
  }

}
export function getPublishList(d:any) {
  if(d.date)
  {
    return request.get<PostsModel>({
      url: Api.Publish+`?page=${d.current}&pageSize=${d.pageSize}&date=${d.date}`,
    });
  }else
  {
    return request.get<PostsModel>({
      url: Api.Publish+`?page=${d.current}&pageSize=${d.pageSize}`,
    });
  }

}
export function getScheduleList(d:any) {
  if(d.date)
  {
    return request.get<PostsModel>({
      url: Api.Schedule+`?page=${d.current}&pageSize=${d.pageSize}&date=${d.date}`,
    });
  }else
  {
    return request.get<PostsModel>({
      url: Api.Schedule+`?page=${d.current}&pageSize=${d.pageSize}`,
    });
  }

}

export function savePosts(d:any)
{
  return request.post({
    url:Api.Edit,
    data:d
  })
}


export function deletePosts(id:any)
{
  return request.post({
    url:Api.Delete+'?id='+id,
    data:{}
  })
}

export function getPosts(id:any)
{
  return request.get<PostsModel>({
    url: Api.Detail+`?id=${id}`,
  });
}

export function getAllPosts(d:any)
{
  return request.get<PostsModel>({
    url: Api.All+`?page=${d.current}&pageSize=${d.pageSize}`,
  });
}

export function saveMeta(d:any)
{
  return request.post<postMetaModel>({
    url:Api.EditMeta,
    data:d
  });
}

